package org.elsfs.cloud.common.mybatis.ext.db;


import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.DeleteSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.InsertSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryListSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryOneSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryPageSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.UnionSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.UpdateSqlExecutor;


/**
 * VEF SQL执行器工厂实现
 *

 */
@RequiredArgsConstructor
public class VefSqlExecutorFactory implements SqlExecutorFactory {

    /**
     * 通用SQL执行器
     */
    private final GenericSqlExecutor genericSqlExecutor;

    /**
     * 查询单条数据
     *
     * @param clazz 数据项类
     * @return SQL执行器
     */
    @Override
    public <R> QueryOneSqlExecutor<R> queryOne(Class<R> clazz) {
        return new QueryOneSqlExecutor<>(this.genericSqlExecutor, clazz);
    }

    /**
     * 查询列表数据
     *
     * @param clazz 数据项类
     * @return SQL执行器
     */
    @Override
    public <R> QueryListSqlExecutor<R> queryList(Class<R> clazz) {
        return new QueryListSqlExecutor<>(this.genericSqlExecutor, clazz);
    }

    /**
     * 查询分页数据
     *
     * @param pageable 分页对象
     * @param clazz    数据项类
     * @return SQL执行器
     */
    @Override
    public <R> QueryPageSqlExecutor<R> queryPage(IPage<R> pageable, Class<R> clazz) {
        return new QueryPageSqlExecutor<>(this.genericSqlExecutor, pageable, clazz);
    }

    /**
     * 联合数据查询
     *
     * @param clazz 数据项类
     * @return SQL执行器
     */
    @Override
    public <R> UnionSqlExecutor<R> unionQuery(Class<R> clazz) {
        return new UnionSqlExecutor<>(this.genericSqlExecutor, clazz);
    }

    /**
     * 插入数据
     *
     * @return SQL执行器
     */
    @Override
    public InsertSqlExecutor insert() {
        return new InsertSqlExecutor(this.genericSqlExecutor);
    }

    /**
     * 更新数据
     *
     * @return SQL执行器
     */
    @Override
    public UpdateSqlExecutor update() {
        return new UpdateSqlExecutor(this.genericSqlExecutor);
    }

    /**
     * 删除数据
     *
     * @return SQL执行器
     */
    @Override
    public DeleteSqlExecutor delete() {
        return new DeleteSqlExecutor(this.genericSqlExecutor);
    }
}
